package pers.amos.edu.service;


import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import pers.amos.edu.mapper.*;
import pers.amos.edu.pojo.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
@Transactional
public class ExaminationService {

    @Resource
    private ExaminationPaperMapper examinationPaperMapper;

    @Resource
    private ExaminationQuestionsMapper examinationQuestionsMapper;

    @Resource
    private ExaminationResultTypeMapper examinationResultTypeMapper;

    @Resource
    private ExaminationResultMapper examinationResultMapper;

    @Resource
    private ExaminationResultShareMapper shareMapper;

    public List<ExaminationPaperEntity> getExaminationPaperList() {
        return examinationPaperMapper.getExaminationPaperList();
    }
    
    public List<ExaminationQuestionsEntity> getExaminationQuestionsList(int paperId) {
        return examinationQuestionsMapper.getExaminationQuestionsList(paperId);
    }
    
    public List<ExaminationQuestionsEntity> getExaminationQuestionsListByQuestionId(int questionId) {
        return examinationQuestionsMapper.getExaminationQuestionsListByQuestionId(questionId);
    }

    public List<ExaminationResultTypeEntity> getExaminationResultTypeList(List<Integer> idList) {
        return examinationResultTypeMapper.selectByIdList(idList);
    }

    
    public ExaminationPaperEntity getExaminationPaperById(int id) {
       // return examinationPaperMapper.selectByPrimaryKey(id);
        return examinationPaperMapper.getExaminationPaperById(id);
    }

    
    public void insertExaminationResult(ExaminationResultEntity ere) {
        ere.setExaminationTime(new Date());
        examinationResultMapper.insert(ere);
    }
    
    public List<ExaminationResultEntity> getExaminationResultListByUserId(String openId) {
        ExaminationResultEntity examinationResultEntity = new ExaminationResultEntity();
        examinationResultEntity.setOpenId(openId);
        return examinationResultMapper.select(examinationResultEntity);
    }

    
    public ExaminationResultTypeEntity getExaminationResultTypeById(int id) {
        return examinationResultTypeMapper.selectByPrimaryKey(id);
    }

    public void insertExaminationResultByShare(ShareExminationPaperEntity entity) {
        entity.setCreateTime(new Date());
        shareMapper.insert(entity);
    }

    public List<ShareExminationPaperEntity> getMyExaminationPaper(String openId) {


        return shareMapper.getMyShareReusltList(openId);
    }
}


